/*
 * @Author: fengshan0525 2735332396@qq.com
 * @Date: 2023-03-19 15:53:07
 * @LastEditors: fengshan@0525 3183359488@qq.com
 * @LastEditTime: 2023-05-25 15:47:08
 * @FilePath: \nest-template\src\roles\roles.controller.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { RolesService } from './roles.service';
import {
  Controller,
  Post,
  Get,
  Body,
  Req,
  Delete,
  Query,
  ValidationPipe,
  UsePipes,
  Param,
  UseGuards,
} from '@nestjs/common';
import { AmdinRole } from '@libs/db/models/role.model';
import { ApiTags } from '@nestjs/swagger';
import { RoleGuard } from 'src/guards/role.guard';
import { Roles } from 'src/decorations/role.decorator';

@ApiTags('角色')
@Controller('roles')
@UseGuards(RoleGuard)
export class RolesController {
  constructor(private readonly rolesService: RolesService) {}

  @UsePipes(new ValidationPipe())
  @Post('create')
  @Roles(['admin'])
  addRole(@Body() body: AmdinRole) {
    return this.rolesService.create(body);
  }

  @Get('detail/:id')
  getRole(@Param() param) {
    return this.rolesService.getRole(param.id);
  }

  @Post('list')
  queryRoles(@Body() body) {
    return this.rolesService.findAll(body);
  }

  @Delete('delete/:id')
  @Roles(['admin'])
  delRole(@Param() param) {
    return this.rolesService.remove(param.id);
  }

  @UsePipes(new ValidationPipe())
  @Post('update')
  @Roles(['admin'])
  updateRole(@Body() body: AmdinRole) {
    return this.rolesService.update(body);
  }
}
